package com.example.demo.util;

import com.example.demo.entity.Cart;
import lombok.Data;

import java.io.Serializable;

/**
 * 购物车的缓存类，只缓存必要的字段，节约内存
 */
public class CartCacheObject implements Serializable {
    private String productId;
    private String userId;
    private String productName;
    private String productNum;
    private String cartId;
    private String productPrice;

    public static CartCacheObject convert(Cart cart) {
        CartCacheObject cartCacheObject = new CartCacheObject();
        cartCacheObject.setCartId("" + cart.getId());
        cartCacheObject.setProductId("" + cart.getProduct_id());
        cartCacheObject.setProductName(cart.getProduct_name());
        cartCacheObject.setUserId(""+cart.getUser_id());
        cartCacheObject.setProductNum("" + cart.getProduct_num());
        cartCacheObject.setProductPrice(""+cart.getProduct_price());
        return cartCacheObject;
    }

    public Cart toCart() {
        Cart cart = new Cart();
        cart.setUser_id(new Long(userId));
        cart.setProduct_name(productName);
        cart.setProduct_num(new Long(productNum));
        cart.setProduct_id(new Long(productId));
        cart.setId(new Long(cartId));
        cart.setProduct_price(new Float(productPrice));
        return cart;
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getProductNum() {
        return productNum;
    }

    public void setProductNum(String productNum) {
        this.productNum = productNum;
    }

    public String getCartId() {
        return cartId;
    }

    public void setCartId(String cartId) {
        this.cartId = cartId;
    }

    public String getProductPrice() {
        return productPrice;
    }

    public void setProductPrice(String productPrice) {
        this.productPrice = productPrice;
    }
}
